package com.qing.thread.pool;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池
 */
public class ThreadPool {
    public static void main(String[] args) {
        //创建线程池的大小
        //创建服务
        ExecutorService service = Executors.newFixedThreadPool(10);

        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        //submit有返回值
        service.submit(new MyThread());
        service.submit(new MyCallableThread());

        //关闭服务
        service.shutdown();
    }
}

class MyThread implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
    }
}

class MyCallableThread implements Callable {

    @Override
    public Boolean call() {
        System.out.println("实现Callable类");
        return true;
    }
}
